package easymall.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import easymall.dao.UserDao;
import easymall.po.User;

@Service("userService")
public class UserServiceImpl implements UserService {
	
	@Autowired
	private MongoTemplate mongoTemplate;
	
	@Autowired
	private UserDao userDao;
	
	@Override
	public User login(String username) {
		
		// TODO Auto-generated method stub
				Query query = new Query();
				String collectionName = "user";
				query.addCriteria(Criteria.where("username").is(username));
				List<User>users = mongoTemplate.find(query, User.class,collectionName);
//				System.out.println(users.get(0));
				if(users.size()!=0)
					return users.get(0);
				else
					return userDao.login(username);
}
	@Override
	public int regist(User user) {
		// TODO Auto-generated method stub
		return userDao.regist(user);
	}
}